﻿
<ControlValueProperty("Anaual")> _
Partial Class WebForm_CommonControl_AnnualControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DataBinding
        ' Me.LoadData()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '   Me.LoadData()
            RaiseEvent Loaded(Me, New EventArgs)
        End If
    End Sub

    Protected Sub ddlAnual_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAnual.SelectedIndexChanged
        Me.LoadData()
        RaiseEvent Changed(Me, New EventArgs)
    End Sub

    Protected Sub ddlAnual_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAnual.Init
        Me.LoadData()
    End Sub
End Class

Partial Class WebForm_CommonControl_AnnualControl
#Region "BLL"
    Private Sub LoadData()
        If Me.ddlAnual.Items.Count = 0 Then
            Me.BindDDLAnual()
        End If
    End Sub

    Public Sub BindDDLAnual()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        Dim d As Date = Date.Now.AddYears(1)

        Me.ddlAnual.Items.Clear()
        'For i As Integer = 0 To Years - 1
        For i As Integer = d.Year To Me.MinYear Step -1

            Dim li As New ListItem
            li.Value = d.Year
            li.Text = d.ToString("yyyy")
            Me.ddlAnual.Items.Add(li)

            d = d.AddYears(-1)
        Next

        'Me.ddlAnual.Items.Insert(0, MyObj.GetDDLSelectAllItem())
        Me.ddlAnual.SelectedValue = Date.Now.Year
    End Sub

    'Public Property Years() As Integer
    '    Get
    '        If ViewState("Years") Is Nothing Then
    '            Return 10
    '        End If
    '        Return ViewState("Years")
    '    End Get
    '    Set(ByVal value As Integer)
    '        ViewState("Years") = value
    '    End Set
    'End Property

    Public Property MinYear() As Integer
        Get
            If ViewState("MinYear") Is Nothing Then
                Return 2000
            End If
            Return ViewState("MinYear")
        End Get
        Set(ByVal value As Integer)
            ViewState("MinYear") = value
        End Set
    End Property

    Public ReadOnly Property RequiresDataBinding() As Boolean
        Get
            If Me.ddlAnual.Items.Count = 0 Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property

    Public Property AutoPostBack() As Boolean
        Get
            Return Me.ddlAnual.AutoPostBack
        End Get
        Set(ByVal value As Boolean)
            Me.ddlAnual.AutoPostBack = value
        End Set
    End Property

    Public Property Anaual() As String
        Get
            If Me.RequiresDataBinding = True Then
                Me.BindDDLAnual()
            End If

            Return Me.ddlAnual.SelectedValue
        End Get
        Set(ByVal value As String)
            Me.ddlAnual.SelectedValue = value
        End Set
    End Property

    Public ReadOnly Property AnaualText() As String
        Get
            Return New Date(Me.ddlAnual.SelectedValue, 1, 1).ToString("yyyy")
        End Get
    End Property

    Public Event Loaded(ByVal source As Object, ByVal e As EventArgs)
    Public Event Changed(ByVal source As Object, ByVal e As EventArgs)
#End Region
End Class